<!--  -->
<template>
  <div>
     <div class="datePicker">
        <el-date-picker
          v-model="dateTime"
          format="yyyy - MM - dd "
          value-format="yyyy-MM-dd"
          @change="changeDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </div>
      <div>
        <h2>用户分析</h2>
        <el-row type="flex">
          <div v-for="item in flowdata" :key="item.index">
            <div class="cart">
              <p class="title">{{ item.title }}</p>
              <p class="bold">{{ item.num }}</p>
            </div>
          </div>
        </el-row>
      </div>
  </div>
</template>

<script>
export default {
  name:'flowAnalysis',
  data () {
    return {
      dateTime: [],
      dateRange: [],
      flowdata:[
        {
          title:'访客数',
          num:10
        },
         {
          title:'页面流量',
          num:129
        },
         {
          title:'人均流量',
          num:12
        }
      ]
    }
  },
  watch: {
    dateRange(val) {
      
    }
  },
  mounted() {
    this.defaultTime();
    this.$nextTick(() => {

    })
  },
  methods:{
    defaultTime() {
      let nowdate = new Date(new Date().getTime() - 30 * 24 * 60 * 60 * 1000);
      
      var y = nowdate.getFullYear().toString();
      var m = nowdate.getMonth()+1<10 ? '0' +(nowdate.getMonth()+1).toString():(nowdate.getMonth()+1).toString();
      var d = nowdate.getDate()<10?'0'+(nowdate.getDate()).toString():nowdate.getDate().toString();
      var formatwdate = y+'-'+m+'-'+d;
      console.log(formatwdate)
      //k开始时间
      let startTime = y + "-" + m + "-" + d;
      
      let date = new Date();
      let year = date.getFullYear().toString();
      let month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1).toString()
          : (date.getMonth() + 1).toString();
      let day =
        date.getDate() < 10
          ? "0" + date.getDate().toString()
          : date.getDate().toString();
      // //结束时间
      let endTime = year + "-" + month + "-" + day;
      this.dateTime = [startTime, endTime];
      // this.dateRange = this.getDateInfo(startTime, endTime);
    },
    getDateInfo(start, end) {
      var result = [];
      var beginDay = start.split("-");
      var endDay = end.split("-");
      var diffDay = new Date();
      var dateList = new Array();
      var i = 0;
      diffDay.setDate(beginDay[2]);
      diffDay.setMonth(beginDay[1] - 1);
      diffDay.setFullYear(beginDay[0]);
      result.push(start);
      while (i == 0) {
        var countDay = diffDay.getTime() + 24 * 60 * 60 * 1000;
        diffDay.setTime(countDay);
        dateList[2] = diffDay.getDate();
        dateList[1] = diffDay.getMonth() + 1;
        dateList[0] = diffDay.getFullYear();
        if (String(dateList[1]).length == 1) {
          dateList[1] = "0" + dateList[1];
        }
        if (String(dateList[2]).length == 1) {
          dateList[2] = "0" + dateList[2];
        }
        result.push(dateList[0] + "-" + dateList[1] + "-" + dateList[2]);
        if (
          dateList[0] == endDay[0] &&
          dateList[1] == endDay[1] &&
          dateList[2] == endDay[2]
        ) {
          i = 1;
        }
      }
      // console.log(result);
      return result;
    },
    changeDate(val) {
      console.log(val);
      this.dateRange = this.getDateInfo(val[0], val[1]);
    },
  }
}
</script>

<style  scoped>
.datePicker {
  text-align: left;
  margin: 30px 20px;
}

h2 {
  font-size: 16px;
  text-align: left;
  padding-left: 20px;
  margin: 30px 0;
}
.title {
  text-align: left;
  line-height: 50px;
}
.bold {
  font-size: 24px;
  font-weight: 700;
  color: #4d4d4d;
  padding-right: 10px;
  text-align: left;
}
.cart {
  width: 200px;
  height: 100px;
  border: 1px solid #e6e6e6;
  margin-left: 20px;
  padding-left: 30px;
}
</style>
